<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
if($_RQ['op']=='get'){
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$return['member']=$member;
	$return['params']['type']=$_RQ['type']?:0;
	$return['sharedata']=array(
		'title'=>$return['pluginset']['share_title']?:'合伙人记账',
		'desc'=>$return['pluginset']['share_desc']?:'合伙人账本共享，一人编辑，多人查看！',
		'link'=>custom_url('jy_jifee/index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>$return['pluginset']['share_image']?tomedia($return['pluginset']['share_image']):tomedia($return['pluginset']['icon'])
	);
	set_html('title',$return['pluginset']['title']?:'合伙人记账');
	$return['params']['item']=array();
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!$post['title']){
		exi('请输入名称！','erroe');
	}
	$data=array(
		'title'=>trim($post['title']),
		'desc'=>trim($post['desc']),
	);
	$id=intval($post['id']);
	if($id){
		$this->model('model')->check_sub($id);
		pdo_update('jy_jifee_list',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('修改成功！','','get');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['mid']=$_SESSION['uid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_jifee_list',$data);
		exi('增加成功！','','get');
	}
	exi('转账成功！');
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$return['list']=pdo_getslice('jy_jifee_list',$params,array($pindex,$psize),$total,array(),'','createtime desc');
	foreach($return['list'] as $k=>&$item){
		$item['createtime']=date('Y-m-d',$item['createtime']);
		$item['member']=cfc('core')->member_show($item['mid']);
	}
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlook'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$return['list']=pdo_getslice('jy_jifee_list_look',$params,array($pindex,$psize),$total,array(),'','createtime desc');
	foreach($return['list'] as $k=>&$item){
		$item=pdo_get('jy_jifee_list',array('id'=>$item['pid'],'uniacid'=>$_SESSION['uniacid']));
		$item['createtime']=date('Y-m-d',$item['createtime']);
		$item['member']=cfc('core')->member_show($item['mid']);
	}
	exi($return);
}
if($_RQ['op']=='password'){
	$post=get_postdata();
	if(!$post['pid']){
		exi('请输入账本ID！','erroe');
	}
	if(!$post['password']){
		exi('请输入支付密码！','erroe');
	}
	$item=pdo_get('jy_jifee_list',array('id'=>$post['pid'],'password'=>$post['password']));
	if(!$item['id']){
		exi('没有查到该账本，请检查ID和密码！','erroe');
	}
	$data=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'pid'=>trim($post['pid']),
		'createtime'=>TIMESTAMP
	);
	pdo_insert('jy_jifee_list_look',$data);
	exi('设置成功！');
}